//子页面不用iframe，用div展示
var closableTab = {
	
    //添加tab
	addTab:function(tabItem){ //tabItem = {id,name,url,closable}
		var id = "tab_seed_" + tabItem.id;
		var key = tabItem.id - 1;
		var container ="tab_container_" + tabItem.id;

		$("li[id^=tab_seed_]").removeClass("active");
		$("div[id^=tab_container_]").removeClass("active");

		if(!$('#'+id)[0]){
			var li_tab = '<li role="presentation" class="" id="'+id+'"><a href="#'+container+'"  role="tab" data-toggle="tab" style="position: relative;padding:2px 20px 2px 15px">'+tabItem.name;
			if(tabItem.closable){
				li_tab = li_tab + '<i class="glyphicon glyphicon-remove small" tabclose="'+id+'" style="position: absolute;right:4px;top: 4px;"  onclick="closableTab.closeTab(this)"></i></a></li> ';
			}else{
				li_tab = li_tab + '</a></li>';
			}

		 	var tabpanel = '<div role="tabpanel" class="tab-pane" data-index="'+key+'" id="'+container+'" style="width: 100%;">'+
	    					  '正在加载...'+
	    				   '</div>';


			$('.nav-tabs').append(li_tab);
			$('.tab-content').append(tabpanel);
            $('#'+container).html('<div class="row">'+
                '<div class="col-sm-12">'+
                '<div class="card">'+
                '<div class="content content-full-width">'+
                '<!--有效时间-->'+
                '<div class="form-group">'+
                '<label class="col-sm-2 control-label">有效时间</label>'+
                '<div class="col-sm-7">'+
                '<div class="row service-charges">'+
                '<div class="col-sm-5 service-charges-name service-charges-name-0" style="padding-left: 15px;">'+
                '<input type="text" placeholder="开始时间" data-name="begin_time" name="detail['+key+'][begin_time]"  class="form-control datetimepicker" id="datetimepicker_startdate">'+
                '</div>'+
                '<div class="col-sm-5 service-charges-remark service-charges-remark-0">'+
                '<input type="text" placeholder="结束时间"  data-name="end_time" name="detail['+key+'][end_time]" class="form-control datetimepicker" id="datetimepicker_enddate">'+
                '</div>'+
                '</div>'+
                '</div>'+
                '</div>'+
                '<!--投放活动-->'+
                '<div class="form-group">'+
                '<label class="col-sm-2 control-label">投放活动</label>'+
                '<div class="col-sm-7">'+
                '<div class="input-group">'+
                '<input type="hidden" class="form-control" value="0" data-name="act_id" name="detail['+key+'][act_id]"  placeholder="+添加活动" >'+
                '<input type="text" class="form-control" onclick="show_activity_deliveries(this)"  data-name="act_name" name="detail['+key+'][act_name]"  placeholder="+添加活动" aria-label="添加活动">'+
                '<div class="input-group-btn">'+
                '<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">列表活动 <span class="caret"></span></button>'+
                '<input type="text" style="display: none;" class="form-control" value="1" data-name="act_type" name="detail['+key+'][act_type]" placeholder="+活动类型" aria-label="活动类型">'+
                '<ul class="dropdown-menu dropdown-menu-right">'+
                '<li><a href="#" data-val="1" onclick="actType(this)">列表活动</a></li>'+
                '<li><a href="#" data-val="2" onclick="actType(this)">自有活动</a></li>'+
                '</ul>'+
                '</div><!-- /btn-group -->'+
                '</div>'+
                '</div>'+
                '</div>'+
                '<!--更换背景-->'+
                '<div class="form-group backgroundImg-container" >'+
                '<label class="col-sm-2 control-label">更换背景</label>'+
                '<div class="col-sm-7">'+
                '<input type="file" name="upfile" accept="image/gif,image/jpeg,image/png" data-target="uploadImageFile" data-for="detail['+key+'][img_url]" data-preview-file-type="text" class="form-control" value="" title="">'+
                '<input type="hidden"  name="detail['+key+'][img_url]" value="" >'+
                '<span class="help-block">支持PNG、JPG格式，小于50KB</span>'+
            '</div>'+
            '</div>'+
            '<!--触发用户-->'+
            '<div class="form-group">'+
				'<label class="col-sm-2 control-label">触发用户</label>'+
                '<div class="col-sm-7">'+
                '<select class="form-control" data-name="target" name="detail['+key+'][target]">'+
                '<option value="1">所有用户</option>'+
                '</select>'+
                '</div>'+
                '</div>'+
				'</div>'+
                '</div>'+
                '</div>'+
                '</div>');
            // $('#'+container).load(tabItem.url,function(response,status,xhr){
				// if(status=='error'){//status的值为success和error，如果error则显示一个错误页面
				// 	$(this).html(response);
				// }
            // });
		}
		$("#"+id).addClass("active");
		$("#"+container).addClass("active");
        initDatetimepicker('#'+container);
        initUploadImageFile('#'+container);
	},

	//关闭tab
	closeTab:function(item){
		window.pointid--;
		var val = $(item).attr('tabclose');
		var containerId = "tab_container_"+val.substring(9);
   	    
   	    if($('#'+containerId).hasClass('active')){
   	    	$('#'+val).prev().addClass('active');
   	    	$('#'+containerId).prev().addClass('active');
   	    }


		$("#"+val).remove();
		$("#"+containerId).remove();
	}
}